import 'package:bloctest/utils/sp_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:bloctest/utils/Routes.dart';
import 'package:bloctest/utils/RouteUtils.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:oktoast/oktoast.dart';

Size get designSize {
  final firstView = WidgetsBinding.instance.platformDispatcher.views.first;
  final logicShotSize =
      firstView.physicalSize.shortestSide / firstView.devicePixelRatio;
  final logicLongSize =
      firstView.physicalSize.longestSide / firstView.devicePixelRatio;

  const scaleFactor = 0.95;

  return Size(logicShotSize * scaleFactor, logicLongSize * scaleFactor);
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: designSize,
        builder: (_, child) {
          return OKToast(
              child: MaterialApp(
                debugShowCheckedModeBanner: false,
                title: 'Flutter Demo',
                theme: ThemeData(
                    colorScheme:
                        ColorScheme.fromSeed(seedColor: Colors.blueGrey),
                    useMaterial3: true),
                navigatorKey: RouteUtils.navigatorKey,
                onGenerateRoute: Routes.generateRouter,
                initialRoute: RouterPath.tab_page,
                locale: Locale('zh', 'CN'),
                // 应用当前的语言环境
                localizationsDelegates: [
                  RefreshLocalizations.delegate,
                  GlobalMaterialLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                ],
                supportedLocales: [
                  const Locale('en', ''), // 英文
                  const Locale('zh', ''), // 中文
                ],
              ));
        });
  }
}
